import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

const routes = [
  {
    path: "/login",
    name: "login",
    component: () => import("@/views/Login/login.vue"),
  },
  {
    path: "/",
    redirect: "/login",
  },
  {
    path: "/home",
    component: () => import("@/views/Home.vue"),
    redirect: "/principalSheet",
    meta: {
      title: "首页",
      parentPath: "/home",
    },
    children: [
      {
        path: "/principalSheet",
        name: "principalSheet",
        component: () => import("@/views/Login/principalSheet.vue"),
        meta: {
          title: "首页",
          parentPath: "/principalSheet",
        },
      },
      // 页面管理
      {
        path: "/pageManagement",
        name: "pageManagement",
        component: () => import("@/views/PageManagement"),
        redirect: "/pageManagement/productService",
        meta: {
          title: "页面管理",
          parentPath: "/pageManagement",
        },
        children: [
          // 产品服务
          {
            path: "/pageManagement/productService",
            name: "productService",
            component: () => import("@/views/PageManagement/productService"),
            meta: {
              title: "产品服务",
              parentPath: "/pageManagement/productService",
            },
          },
          // 智能养老设备
          {
            path: "/pageManagement/IntelligentElderlyCare",
            name: "IntelligentElderlyCare",
            component: () =>
              import("@/views/PageManagement/intelligentElderlyCare"),
            meta: {
              title: "智能养老设备",
              parentPath: "/pageManagement/IntelligentElderlyCare",
            },
          },
          // 活动资讯
          {
            path: "/pageManagement/moveAbout",
            name: "moveAbout",
            component: () => import("@/views/PageManagement/moveAbout"),
            meta: {
              title: "活动资讯",
              parentPath: "/pageManagement/moveAbout",
            },
          },
          // 智慧养老学院
          {
            path: "/pageManagement/pensionCollege",
            name: "pensionCollege",
            component: () => import("@/views/PageManagement/pensionCollege"),
            meta: {
              title: "智慧养老学院",
              parentPath: "/pageManagement/pensionCollege",
            },
          },
        ],
      },
      // 老人的信息管理
      {
        path: "/informationManagement",
        name: "informationManagement",
        component: () => import("@/views/InformationManagement"),
        redirect: "/informationManagement/personalInformation",
        meta: {
          title: "信息管理",
          parentPath: "/informationManagement",
        },
        children: [
          // 个人信息
          {
            path: "/informationManagement/personalInformation",
            name: "personalInformation",
            component: () =>
              import("@/views/InformationManagement/personalInformation"),
            meta: {
              title: "个人信息",
              parentPath: "/informationManagement/personalInformation",
            },
          },
          // 家属信息
          {
            path: "/informationManagement/familyInformation",
            name: "familyInformation",
            component: () =>
              import("@/views/InformationManagement/familyInformation"),
            meta: {
              title: "家属信息",
              parentPath: "/informationManagement/familyInformation",
            },
          },
          // 预约探视
          {
            path: "/informationManagement/appointmentVisits",
            name: "appointmentVisits",
            component: () =>
              import("@/views/InformationManagement/appointmentVisits"),
            meta: {
              title: "预约探视",
              parentPath: "/informationManagement/appointmentVisits",
            },
          },
          // 定期体检
          {
            path: "/informationManagement/physicalExamination",
            name: "physicalExamination",
            component: () =>
              import("@/views/InformationManagement/physicalExamination"),
            meta: {
              title: "定期体检",
              parentPath: "/informationManagement/physicalExamination",
            },
          },
        ],
      },
      //平台信息
      {
        path: "/terrace",
        name: "terrace",
        component: () => import("@/views/terrace"),
        redirect: "/terrace/essentialInformation",
        meta: {
          title: "平台管理",
          parentPath: "/terrace",
        },
        children:[
          //基本信息
          {
            path: "/terrace/essentialInformation",
            name: "essentialInformation",
            component: () => import("@/views//terrace/essentialInformation"),
            meta: {
              title: "基本信息",
              parentPath: "/terrace/essentialInformation",
            },
          },
          //收入信息
          {
            path: "/terrace/revenueInformation",
            name: "revenueInformation",
            component: () => import("@/views//terrace/revenueInformation"),
            meta: {
              title: "收入信息",
              parentPath: "/terrace/revenueInformation",
            },
          },
          //账号信息
          {
            path: "/terrace/userInformation",
            name: "userInformation",
            component: () => import("@/views//terrace/userInformation"),
            meta: {
              title: "账号信息",
              parentPath: "/terrace/userInformation",
            },
          },
          //公告信息
          {
            path: "/terrace/noticeInformation",
            name: "noticeInformation",
            component: () => import("@/views//terrace/noticeInformation"),
            meta: {
              title: "公告信息",
              parentPath: "/terrace/noticeInformation",
            },
          },
        ]
      },
      
    ],
  },
  //大屏展示
  {
    path: "/bigScreen",
    component: () => import("@/views/componentPage/bigScreen"),
  },
  //天气展示
  {
    path: "/weatherPage",
    component: () => import("@/views/componentPage/weatherPage"),
  },
  //测试
  {
    path: "/homePage",
    component: () => import("@/views/bigPage/homePage"),
  },
  //车辆监控
  {
    path: "/vehicleMonitoring",
    component: () => import("@/views/bigPage/vehicleMonitoring/pageVue"),
  }
];


const router = new VueRouter({
  routes,
});


router.beforeEach((to,from,next) => {
  let toke = JSON.parse(sessionStorage.getItem( 'userMessage' ))
  if(to.path == '/login'){
    if(toke != null) {
      next({path:'/homePage'})
    }else next()
  }else {
    if(toke == null) {
      next({path:'/login'})
    }else next()
  }
})

export default router;
